package com.service.gmall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.service.gmall.common.constant.SysRedisConst;
import com.service.gmall.model.product.BaseCategory2;
import com.service.gmall.model.to.CategoryTreeTo;
import com.service.gmall.product.service.BaseCategory2Service;
import com.service.gmall.product.mapper.BaseCategory2Mapper;
import com.service.starter.cache.annotation.GmallCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author alpha
* @description 针对表【base_category2(二级分类表)】的数据库操作Service实现
* @createDate 2022-08-22 22:45:59
*/
@Service
public class BaseCategory2ServiceImpl extends ServiceImpl<BaseCategory2Mapper, BaseCategory2>
    implements BaseCategory2Service{

    @Autowired
    BaseCategory2Mapper baseCategory2Mapper;
    /**
     * @param category1Id
     * @description: 通过一级目录ID查询二级目录
     * @return: java.util.List<com.service.gmall.model.product.BaseCategory2>
     * @author: alpha
     * @date: 2022/8/22 22:57
     */
    @Override
    public List<BaseCategory2> getCategory2(String category1Id) {
        List<BaseCategory2> baseCategory2s = baseCategory2Mapper.selectList(new LambdaQueryWrapper<BaseCategory2>()
                .eq(BaseCategory2::getCategory1Id, category1Id));
        return baseCategory2s;
    }

    @GmallCache(cacheKey = SysRedisConst.CACHE_CATEGORYS)
    @Override
    public List<CategoryTreeTo> getAllCategoryTree() {
        return baseCategory2Mapper.getAllCategoryTree();
    }
}




